package com.jiepuxun.demo.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
public class KafkaService {

    @Autowired
    private KafkaTemplate<String,Object> template;

    public void send(String msg){
        this.template.send("test","userId",msg);
        System.out.println("====================set finished======================");
    }

    @KafkaListener(topics = "test")
    public void onMessage(ConsumerRecord<?,?> record){
        System.out.println("=======================on message=============================");
        System.out.println("topic -> "+record.topic());
        System.out.println("partition -> "+record.partition());
        System.out.println("get message -> "+record.value());
    }
}
